import "../../../css/Sidebar.css";
import urlHook from "@page/common/utils/urlHook";
function SideBarUnit(props) {
    const {name,taburl,tabid,updateMenu,menuStatus,iconClass,iconActiveClass} = props;
    //定义全局变量 const [scope值，更新方法] = React.useState({初始化的值});
    const [sideBarStatus, updateSideBarStatus] = React.useState({
        name: name,
        taburl:taburl,
        isshow:menuStatus.showGroup,
        isselected:menuStatus.selectedGroup,
        tabid:tabid
    });

    //更新视图数据 私有的方法前缀用_
    function _updateData(value) {
        let newValue = { ...sideBarStatus, ...value };
        updateSideBarStatus(newValue);
    }

    React.useEffect(() => {
        console.log("refresh view");
    });
    /*_updateData(
        (sideBarStatus.isshow = menuStatus.showGroup),
        (sideBarStatus.isselected = menuStatus.selectedGroup)
    )*/
    return (
        ((iconClass.indexOf("subNav-icon")>-1||iconActiveClass.indexOf("subNav-icon-active")>-1)?
        <li className={menuStatus.showGroup[sideBarStatus.tabid]?menuStatus.selectedGroup[sideBarStatus.tabid]?"zen_t-c zen_w-180 zen_h-40 zen_cur-p zen_bg-FFFFFF":"zen_w-180 zen_h-40 zen_cur-p":"zen_hide"} onClick={() =>selectTab(sideBarStatus,menuStatus,updateMenu)}>
            <a>
                <div className="zen_w-125 zen_t-l zen_313131 zen_h-40 zen_l-h-40 zen_v-t zen_il-bl zen_fs-12">{sideBarStatus.name}</div>
            </a>
        </li>:
        <li className={menuStatus.showGroup[sideBarStatus.tabid]?menuStatus.selectedGroup[sideBarStatus.tabid]?"zen_w-180 zen_h-40 zen_cur-p zen_bg-13b5bd":"zen_w-180 zen_h-40 zen_cur-p":"zen_hide"} onClick={() =>selectTab(sideBarStatus,menuStatus,updateMenu)}>
            <a>
                <div className={menuStatus.selectedGroup[sideBarStatus.tabid]?"sideBar-nav-icon "+iconActiveClass:"sideBar-nav-icon "+iconClass}></div>
                <div className="zen_w-125 zen_t-l zen_FFFFFF zen_h-40 zen_l-h-40 zen_v-t zen_il-bl zen_fs-14">{sideBarStatus.name}</div>
            </a>
        </li>
        )
    )
}
function selectTab(sideBarStatus,menuStatus,updateMenu) {
    let isSelected = menuStatus.selectedGroup.concat();
    isSelected.map((item, index) => {
        isSelected[index] = false;
    })
    isSelected[sideBarStatus.tabid] = true;
    updateMenu(isSelected);
    let newHMSTab = [11];
    if(newHMSTab.indexOf(sideBarStatus.tabid)!=-1){
        $state.go({
            stateName: sideBarStatus.taburl
        });
    }else{
       Uts.routeToDomain('hms',sideBarStatus.taburl);
    }
}
export default SideBarUnit;